package com.mate.cloud.lottery.service;

import com.mate.cloud.lottery.domain.LotteryItem;
import com.mate.cloud.lottery.domain.LotteryRecord;
import com.mate.cloud.lottery.mapper.LotteryRecordMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class AsyncLotteryRecordTask {

    @Resource
    LotteryRecordMapper lotteryRecordMapper;


    @Async("lotteryServiceExecutor")
    public void saveLotteryRecore(String accountIp, LotteryItem lotteryItem, String prizeName) {
        log.info(Thread.currentThread().getName()+"-----saveLotteryRecord");
        // 存储中奖信息
        LotteryRecord record = new LotteryRecord();
        record.setAccountIp(accountIp);
        record.setItemId(lotteryItem.getId());
        record.setPrizeName(prizeName);
        record.setCreateTime(LocalDateTime.now());
        lotteryRecordMapper.insert(record);
    }
}
